using System;
using System.IO;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TMFileManager {
    public partial class PropertiesDialog : Form {
        public PropertiesDialog(TreeMapNode node) {
            InitializeComponent();
            txtPath.Text = Path.GetFileName(node.getLabel());
            lblLocation.Text = Path.GetDirectoryName(node.getLabel());
            if (File.Exists(node.getLabel())) {
                imgIcon.Image = Icon.ExtractAssociatedIcon(node.getLabel()).ToBitmap();
                imgIcon.Size = imgIcon.Image.Size;
            }
            string label;
            if (node.getWeight() < 1024) {
                label = node.getWeight() + " B (" + node.getWeight().ToString("N0") + " bytes)";
            } else if (node.getWeight() < 1024 * 1024) {
                label = (node.getWeight() / 1024D).ToString("N2") + " KB (" + node.getWeight().ToString("N0") + " bytes)";
            } else if (node.getWeight() < 1024 * 1024 * 1024) {
                label = (node.getWeight() / (1024D * 1024D)).ToString("N2") + " MB (" + node.getWeight().ToString("N0") + " bytes)";
            } else {
                label = (node.getWeight() / (1024D * 1024D * 1024D)).ToString("N2") + " GB (" + node.getWeight().ToString("N0") + " bytes)";
            }
            lblSize.Text = label;

            DateTime creationTime = File.GetCreationTime(node.getLabel());
            lblCreated.Text = creationTime.ToLongDateString() + ", " + creationTime.ToLongTimeString();
            DateTime modificationTime = File.GetLastWriteTime(node.getLabel());
            lblModified.Text = modificationTime.ToLongDateString() + ", " + modificationTime.ToLongTimeString();
            DateTime accessedTime = File.GetLastAccessTime(node.getLabel());
            lblAccessed.Text = accessedTime.ToLongDateString() + ", " + accessedTime.ToLongTimeString();
        }
    }
}